package com.icehand.springdocker.demo.controller;

import com.icehand.springdocker.demo.convert.UserDtoMapper;
import com.icehand.springdocker.demo.po.User;
import com.icehand.springdocker.demo.vo.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class DemoController {
    @Autowired
    private UserDtoMapper userDtoMapper;

    @RequestMapping("/demo")
    public String demo(){
        return "hello world";
    }

    @RequestMapping("/add")
    public UserDto addUser(User user){
        UserDto userDto = userDtoMapper.user2Dto(user);
        log.info("Add UserDto 【{}】", userDto.toString());
        return userDto;
    }

    @RequestMapping("/get")
    public UserDto get(UserDto userDto){
        User user = userDtoMapper.dot2User(userDto);
        log.info("get User 【{}】",user.toString());
        return userDto;
    }

    @RequestMapping("/users")
    public List<UserDto> users(User user){
       List<User> users = new ArrayList<>();
       users.add(user);
       User user2 = new User();
       user2.setAvatar("test");
       user2.setGender(true);
       user2.setUsername("哈");
       user2.setPassword("XXXXXX");
       users.add(user2);
        log.info("Users 【{}】",users.toString());
        return userDtoMapper.users2UserDtos(users);
    }
}
